#!/bin/bash
#Author:lixinglilove@hotmail.com
#CreateTime:20200710
#离线文件需要和脚本文件同一目录
PyDown="https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz"
FileName="Python-2.7.18.tgz"
DirName=$(echo $FileName |awk -F ".tgz" '{print $1}')
echo "当前Python版本为" $(python -V)
echo "升级Python版本为：2.7.18"
sleep 1

which wget
if [ $? -eq 1 ];then
	echo "Please install wget tools:yum -y install wget"
	exit 1
fi

echo "解压安装包"
tar zxvf $FileName
cd $DirName
./configure --prefix=/usr/local && make && make altinstall

if [ $? -eq 1 ];then
	echo "编译异常，请检查gcc是否安装:yum -y install gcc"
	exit 1
fi

mv /usr/bin/python /usr/bin/python2.7.5
ln -s /usr/local/bin/python2.7 /usr/bin/python
sed -i 's/python/python2.7.5/g'  /usr/bin/yum
sed -i 's/python/python2.7.5/g'  /usr/libexec/urlgrabber-ext-down
echo "当前Pyton版本为" $(python -V)
rm -rf $DirName
rm -rf $FileName